home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / win / steph1b0.zip / EDITOR.C < prev    next >
C/C++ Source or Header  |  1994-09-27  |  6KB  |  266 lines

  1. /* EDITOR.C */
  2. /* Copyright (c) S Morphet, 1993,1994 */
  3. /* Editor functions for attachment to a Steph window. */
  4.  
  5. /*
  6.    This example program is designed to show how a simple text
  7.    editor can be written to use the Steph system.
  8.  
  9.    The code can be found in the files EDITFN.C and EDITFN.H.
  10.  
  11.    Note: This editor is demonstration code only.  It lacks many
  12.     features that might be expected of a text editor.
  13.  
  14.    Please feel free to use this code as the basis for your own
  15.    editors for Steph.
  16.  
  17.    To compile: Your project should include EDITOR.C EDITFN.C and
  18.     a Steph library such as STEPH_M.LIB
  19.  
  20.    The file DEMO.C includes examples of dialogue boxes etc.
  21. */
  22.  
  23. #include "d:\cwork\steph\include\steph.h"
  24. #include "d:\cwork\steph\editor\editfn.h"
  25.  
  26. #include "d:\cwork\steph\dialogue\dialogue.h"
  27. #include "d:\cwork\steph\dialogue\disk.h"
  28.  
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <conio.h>
  32. #include <string.h>
  33.  
  34. #define _ED_VER_ "v1.5"
  35.  
  36.  
  37. void about( void );
  38. void bufferit( void );
  39. void openfile( void );
  40. void fnexit( void );
  41.  
  42. void getdirs( void );
  43.  
  44. void mysysfilter( void );
  45. void mysysaction( void );
  46. void myinit( void );
  47.  
  48. void main( void )
  49. {
  50.     /* set up the dialogue box module */
  51.     _dialogue_initialise();
  52.  
  53.     if( !_steph_initialise( M_TEXT ) )
  54.     {
  55.         printf( "Not enough video oomph!" );
  56.         exit(0);
  57.    }
  58.  
  59.    /* set up menus and functions */
  60.     _menu_build( 0, "&File",
  61.             "&About",
  62.             "&Buffer it",
  63.             "&Open",
  64.             "Get &Dir",
  65.             "=",
  66.          "E&xit.",
  67.             NULL );
  68.  
  69.     _menu_functions( 0,
  70.             about,
  71.             bufferit,
  72.             openfile,
  73.             getdirs,
  74.             NOFN,
  75.             fnexit );
  76.  
  77.     _menu_helptext( 0, "Default menu.",
  78.             "Information about editor.",
  79.             "Copy into single buffer.",
  80.             "Open a file.",
  81.             "Get a directory.",
  82.             NOTEXT,
  83.          "Exit the program" );
  84.  
  85.     /* Set up pointer to application initialisation function */
  86.     _steph_initialfunction( myinit );
  87.  
  88.     /* Set up the screen windows */
  89.  
  90.     /* Build the first editor window */
  91.  
  92.    _window_build( 0, WP_MAIN, 10, "Editor Window", editor_filter,
  93.          editor_action, NOFN );
  94.  
  95.     /* Attach mouse functions to the editor window */
  96.  
  97.    _window_mouse_functions( 0, NOFN,
  98.          editor_mouse_maximise,
  99.          editor_mouse_minimise,
  100.          editor_mouse_resize,
  101.          ems_up, ems_down, ems_vdrag, ems_pup, ems_pdown,
  102.          ems_left, ems_right, ems_hdrag, ems_pleft, ems_pright,
  103.          editor_mouse_unselect, editor_mouse_select,
  104.          editor_mouse_activate );
  105.  
  106.     _window_set_draw( 0, WD_COLOUR, NOFN );
  107.  
  108.     /* Another editor window can be created very easily. */
  109.  
  110.     _window_build( 1, WP_BOT, 2, "Editor 2", editor_filter,
  111.             editor_action, NOFN );
  112.  
  113.     _window_set_draw( 1, WD_COLOUR, NOFN );
  114.  
  115.     /* Attach mouse functions to the editor window. */
  116.  
  117.     _window_mouse_functions( 1, NOFN,
  118.          editor_mouse_maximise,
  119.          editor_mouse_minimise,
  120.          editor_mouse_resize,
  121.          ems_up, ems_down, ems_vdrag, ems_pup, ems_pdown,
  122.          ems_left, ems_right, ems_hdrag, ems_pleft, ems_pright,
  123.          editor_mouse_unselect, editor_mouse_select,
  124.          editor_mouse_activate );
  125.  
  126.  
  127.     /* Set up a dialogue box for 'Help' information */
  128.  
  129.     _dbox_build( 0, DB_CENSCR, 48, 8, 3, "About EDITOR.", NOTEXT );
  130.     _dbox_c_label( 0, 0, 2, 2, "EDITOR " _ED_VER_ ". Steph Demonstration Program." );
  131.     _dbox_c_label( 0, 1, 2, 4, "Stephen Morphet.  September 1994." );
  132.     _dbox_c_button( 0, 2, 2, 6, 6, "&OK", EXIT, NOFN );
  133.  
  134.  
  135.     /* Create a file open box */
  136.  
  137.     _dbuild_fileopen( 1 );
  138.  
  139.     /* Put text on the speed bar */
  140.  
  141.     _speed_setbar( _s_strdup("EDITOR " _ED_VER_ ". Press ALT for menu.") );
  142.  
  143.     /* Set up a system level key trap for F1. */
  144.  
  145.     _window_setsyskey( mysysfilter, mysysaction );
  146.  
  147.     /* Set up the editor, then start Steph. */
  148.  
  149.     editor_initialise();
  150.  
  151.     _steph_go();
  152.  
  153. }
  154.  
  155.  
  156. /* An exit function, called when user chooses File-Exit. */
  157.  
  158. void fnexit( void )
  159. {
  160.     _steph_closedown();
  161.    exit(0);
  162. }
  163.  
  164.  
  165. /* The initialise function opens the second window. */
  166.  
  167. void myinit( void )
  168. {
  169.    /* window 0 (main) is already open */
  170.  
  171.    /* make editor window active, and open the other one */
  172.    _window_make_active( 0 );
  173.    _window_open( 1, OPEN );
  174.  
  175.    /* refresh windows */
  176.    _window_draw();
  177.    _window_refresh_all();
  178.  
  179.    /* turn on the cursor in the editor window */
  180.    ed_put_cursor( 0 );
  181.  
  182. }
  183.  
  184.  
  185. /* The system key filter spots the F1 key */
  186.  
  187. void mysysfilter( void )
  188. {
  189.    if( _window_spec.key1 == 0 )
  190.       if( _window_spec.key2 == 59 )
  191.          _window_spec.syskeyflag = TRUE;
  192. }
  193.  
  194. /* The action function uses dialogue box 0 to give info. */
  195.  
  196. void mysysaction( void )
  197. {
  198.    /* fill in the gaps to attach code to other keystrokes */
  199.    switch( _window_spec.key1 )
  200.    {
  201.       /* nonzero value means it was an ascii key */
  202.       case 0:
  203.       {
  204.          switch( _window_spec.key2 )
  205.          {
  206.             /* list of non ascii keys... */
  207.             case 59:
  208.             {
  209.                _dbox_go(0);
  210.                break;
  211.             }
  212.  
  213.             default:
  214.             {}
  215.          }
  216.  
  217.          break;
  218.       }
  219.  
  220.       default:
  221.       {}
  222.    }
  223. }
  224.  
  225.  
  226. void about( void )
  227. {
  228.     _dbox_go(0);
  229. }
  230.  
  231.  
  232. void bufferit( void )
  233. {
  234.     char* buffer = _ed_makebuffer( _window_spec.active );
  235.     printf("%s", buffer );
  236.     free( buffer );
  237. }
  238.  
  239.  
  240.  
  241. void openfile( void )
  242. {
  243.     _dbox_go(1);
  244.     _ed_readfile( _window_spec.active, "d:\\cwork\\steph\\editor\\test.txt" );
  245.     _window_refresh( _window_spec.active );
  246. }
  247.  
  248.  
  249. void getdirs( void )
  250. {
  251.  
  252.     char *working;
  253.  
  254.     working = _dd_dirdisk();
  255.  
  256.     working = _s_list_insert( working, "Moose", /*_s_list_count(working)*/ 2    );
  257.     //working = _s_list_delete( working, 6 );
  258.  
  259.     while( *working != '\0' )
  260.     {
  261.         printf("%s\n", working);
  262.         working += strlen(working) + 1;
  263.     }
  264.  
  265. }
  266.